package com.wu.shop.module.home.frame.view

import androidx.recyclerview.widget.GridLayoutManager
import com.wkq.base.frame.mosby.delegate.MvpView
import com.wu.common.util.StatusBarUtil
import com.wu.shop.module.home.frame.model.GoodsDescInfo
import com.wu.shop.module.home.ui.adapter.HomeGoodsAdapter
import com.wu.shop.module.home.ui.adapter.HomeTopBannerAdapter
import com.wu.shop.module.home.ui.fragment.HomeFragment
import com.wu.shop.other.WebTestActivity

class HomeView(fragment: HomeFragment) : MvpView {
    var imgUrl="https://t7.baidu.com/it/u=4186210017,3381159435&fm=193&f=GIF"
    var imgUrl12="https://t7.baidu.com/it/u=1070121341,87043257&fm=193&f=GIF"

    var mFragment = fragment

    fun initView() {
        mFragment.binding.sf.setEnableRefresh(false)
        var hight = StatusBarUtil.getStatusBarHeight(mFragment.activity);
        mFragment.binding.rlIco.setPadding(0, hight + 10, 0, 0)
        mFragment.binding.rlSearch.setPadding(0, hight + 10, 0, 0)
        initTop()
        initBottom()
        mFragment.binding.rlCancle.setOnClickListener {
            WebTestActivity.newInstance(mFragment.activity!!,"http://cdnqd1.en90.com/static/baidu/index.html")
        }
    }

    private fun initBottom() {
        mFragment.binding.rvContent.layoutManager = GridLayoutManager(mFragment.activity, 2)
        var goodsAdapter = HomeGoodsAdapter(mFragment.activity!!)
        mFragment.binding.rvContent.adapter = goodsAdapter
        var goodsList = ArrayList<GoodsDescInfo>()

        for (index in 1..10) {
            var info = GoodsDescInfo()
            info.goodsIcon =imgUrl12
            info.goodsId = index.toString()
            info.goodsName = "中秋"
            info.goodsNum = 10
            info.goodsDesc = "中秋节大月饼非常不错可以尝尝!!!"
            goodsList.add(info)
        }
        goodsAdapter.addItems(goodsList)

    }

    private fun initTop() {
        var  banner= HomeTopBannerAdapter(mFragment.activity!!)
        mFragment.binding.vpTop.setAdapter(banner)


        var goodsList = ArrayList<GoodsDescInfo>()

        for (index in 1..10) {
            var info = GoodsDescInfo()
            info.goodsIcon =imgUrl
            info.goodsId = index.toString()
            info.goodsName = "中秋"
            info.goodsNum = 10
            info.goodsDesc = "中秋节大月饼非常不错可以尝尝!!!"
            goodsList.add(info)
        }
        mFragment.binding.vpTop.create(goodsList)
    }

}
